home *** CD-ROM | disk | FTP | other *** search
/ Dr. Windows 3 / dr win3.zip / dr win3 / VISUALBA / BOZOL2.ZIP / CUSTOM.BAS < prev    next >
BASIC Source File  |  1994-02-08  |  2KB  |  79 lines

  1. SUB BROWSE(A$, TopView%, LeftView%,BottomView%, RightView%)
  2. WideNess%=RightView%-LeftView%
  3. Ptr%=1   ' starting byte for view (1 is top of file)
  4. Offset%=0  ' horizontal movement
  5. DO
  6. TempPtr% = Ptr% : Temp% = TopView%
  7. DO
  8. ' TempPtr% is byte position of current line, calculate offset of end of line
  9. eol% = Instr(Mid$(A$,TempPtr%),Chr$(13))
  10. ' if there are no more carriage returns, then eol% is the end of A$
  11. if eol%=0 then eol%=LEN(A$) ELSE DECR eol%   ' DECR: do not show the CR
  12. ' get the current line as Curr$
  13. Curr$ = Mid$(A$, TempPtr%,eol%)
  14. ' display the current line
  15. Locate Temp%, LeftView%
  16. PRINT Mid$(Curr$+Space$(WideNess%+Offset%), 1+Offset%,WideNess%)
  17. ' increment the pointer to the next line to display in the window
  18. TempPtr% = Instr(TempPtr%, A$, Chr$(13)) + 2  ' +2 for CRLF pair
  19. ' if we have reached the end then we don't show any more
  20. If TempPtr%=2 Then TempPtr%=LEN(A$)
  21. ' get ready to display the next line...
  22. INCR Temp%
  23. ' inless we are done, in which case, we have finished with the screen
  24. if Temp% > BottomView% THEN Exit LOOP
  25. LOOP
  26.  
  27. ' now, we need a keystroke to tell us which way to browse around
  28.  
  29. DO:LOOP WHILE NOT INSTAT
  30.  
  31. KB$=INKEY$
  32.     SELECT CASE KB$
  33.     CASE CHR$(0,&H50)  'dn arrow
  34.         IF TempPtr% < LEN(A$) THEN
  35.             Ptr%=Instr(Ptr%, A$, Chr$(13) ) + 2
  36.  
  37.     ELSE
  38.             Sound 100,.1   ' we are at the end
  39.     END IF
  40.  
  41.     CASE CHR$(0,&H48)  'up arrow
  42.         IF Ptr% > 1 THEN
  43.             ' search backwards for a CR or 1
  44.         DECR Ptr%:IF Ptr%>1 then DECR Ptr%
  45.         DO:DECR Ptr%:LOOP UNTIL Mid$(A$, Ptr%, 1)=CHR$(13) OR Ptr%=1
  46.         IF Ptr%>1 THEN INCR Ptr%:INCR Ptr%
  47.         ELSE
  48.             Sound 100,.1  ' we are at the beginning
  49.         END IF
  50.     CASE CHR$(0,&H47)  'home
  51.         If Offset% THEN Offset% = 0 ELSE Ptr%=1
  52.     CASE CHR$(0, &H4D)  ' right arrow
  53.         INCR Offset%
  54.     CASE CHR$(0,&H4B)   ' left arrow
  55.         If Offset% THEN DECR Offset%
  56.     CASE CHR$(0,&H51)  ' page down
  57.         FOR pd = TopView% to BottomView%-1
  58.         OldPtr%=Ptr%
  59.         Ptr%=Instr(Ptr%, A$, Chr$(13) ) + 2
  60.         if Ptr%=2 then Ptr%=OldPtr%:Exit FOR
  61.         Next Pd
  62.     CASE CHR$(0, &H49)  ' page up
  63.         FOR pd = TopView% to BottomView% -1
  64.         IF Ptr% > 1 THEN
  65.             ' search backwards for a CR or 1
  66.         DECR Ptr%:IF Ptr%>1 then DECR Ptr%
  67.         DO:DECR Ptr%:LOOP UNTIL Mid$(A$, Ptr%, 1)=CHR$(13) OR Ptr%=1
  68.         IF Ptr%>1 THEN INCR Ptr%:INCR Ptr%
  69.         ELSE
  70.         EXIT FOR
  71.         END IF
  72.         NEXT Pd
  73.     CASE ELSE
  74.     END SELECT
  75. IF KB$=CHR$(27) THEN EXIT LOOP
  76. LOOP
  77. '''' THAT'S ALL FOLKS!    EDITING ROUTINES TO FOLLOW!
  78. END SUB
  79.